package ua.kpi.oblamskyiv;

import ua.kpi.oblamskyiv.factory.HardcodedQuestionsFactory;
import ua.kpi.oblamskyiv.io.ClientIO;

public class ConsoleClientApp {
    private ClientIO clientIO = new ClientIO();
    private Tester tester = new Tester(new HardcodedQuestionsFactory());

    public void appStateIteration() {
        clientIO.printMainMenu();

        switch(clientIO.getMenuChoice()) {
            case ClientIO.AUTHORIZE:
                authorization();
                break;
            case ClientIO.TEST:
                test();
                break;
            case ClientIO.EXIT:
                System.exit(0);
            default:
                throw new IllegalArgumentException();
        }
    }

    private void authorization() {
        if (LoginManager.getInst().isLogged()) {
            LoginManager.getInst().logout();
        } else {
            LoginManager.getInst().login();
        }
    }

    private void test() {
        TestStats stats = tester.takeTest(LoginManager.getInst().getUser());
        clientIO.writeStats(stats);
    }

    public static void main(String[] args) {
        ConsoleClientApp app = new ConsoleClientApp();
        while(true) {
            app.appStateIteration();
        }
    }
}
